<template>
  <el-dialog
    title="导出"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose"
  >
    <template>
      <el-radio v-model="type" label="1">仅导出默认数据</el-radio>
      <el-radio v-model="type" label="2">导出全部数据</el-radio>
    </template>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="success">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { customerExport, queryExportDomain } from '@/api'
  export default {
    name: 'xiaohu',
    data() {
      return {
        dialogVisible: false,
        type: '1',
        temp: {},
        kv: {},
        exportDomain: null
      }
    },
    created() {

    },
    methods: {
      async open(temp, list) {
        await this.getExportDomain()
        if (temp && list) {
          this.temp = { ...temp }
          this.kv = { ...list }
          this.dialogVisible = true
        }
      },
      // 获取导出域名
      async getExportDomain() {
        const res = await queryExportDomain()
        if (res && res.data) {
          this.exportDomain = res.data
        }
      },
      async success() {
        const params = {
          type: this.type * 1,
          orderBy: this.temp.orderBy,
          kv: this.kv,
          paramInfo: { ...this.temp }
        }
        await customerExport(params).then((res) => {
          window.open(`${this.exportDomain}/page/export/frame?key=${res.data}`, '_blank')
        })
        this.dialogVisible = false
      },
      handleClose(done) {
        this.dialogVisible = false
      }
    }
  }

</script>
